using SqlSugar;
using IM.Easy.Core.Audit;

namespace IM.Easy.Entity.Scheduled
{
    /// <summary>
    /// 任务触发器表
    /// </summary>
    [SugarTable("JobTrigger")]
    public class JobTrigger : AuditableGuidEntity, IActive
    {
        /// <summary>
        /// 关联任务的ID
        /// </summary>
        [SugarColumn(ColumnName = "JobId")]
        public Guid JobId { get; set; }

        /// <summary>
        /// 触发器类型，如 Cron 或 Simple
        /// </summary>
        [SugarColumn(ColumnName = "Type", Length = 10)]
        public string Type { get; set; }

        /// <summary>
        /// Cron 表达式，用于 Cron 调度
        /// </summary>
        [SugarColumn(ColumnName = "Cron", Length = 100)]
        public string? Cron { get; set; }

        /// <summary>
        /// 间隔时间（单位：秒），用于简单调度
        /// </summary>
        [SugarColumn(ColumnName = "Interval")]
        public int Interval { get; set; }

        /// <summary>
        /// 轮询次数
        /// </summary>
        [SugarColumn(ColumnName = "Repeat")]
        public int Repeat { get; set; }

        /// <summary>
        /// 有效期开始
        /// </summary>
        [SugarColumn(ColumnName = "EffictStartTime")]
        public DateTime? EffictStartTime { get; set; }

        /// <summary>
        /// 有效期结束
        /// </summary>
        [SugarColumn(ColumnName = "EffictEndTime")]
        public DateTime? EffictEndTime { get; set; }

        /// <summary>
        /// 启动模式
        /// </summary>
        [SugarColumn(ColumnName = "StartMode")]
        public TriggerStartMode StartMode { get; set; }

        /// <summary>
        /// 触发器是否启用（true：启用，false：禁用）
        /// </summary>
        [SugarColumn(ColumnName = "IsActive")]
        public bool IsActive { get; set; }

    }

    public enum TriggerStartMode
    {
        /// <summary>
        /// 手动模式
        /// </summary>
        Manual,

        /// <summary>
        /// 立即启动
        /// </summary>
        Immediate,

        /// <summary>
        /// 预约模式--指定具体时间启动
        /// </summary>
        Scheduled,
    }
}
